package com.palm.core.translator;

import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;

public class FormatTranslator implements Translator{
    Format format;
    public FormatTranslator(String format){
        if(format.indexOf("#")>-1){
            this.format= new DecimalFormat(format);
        }else{
            this.format=new SimpleDateFormat(format);
        }
    }
    @Override
    public Object translate(Object target, String filedName, Object value) {
        if(value==null){
            return null;
        }
        return format.format(value);
    }
}
